package com.zsc.edu.gateway.modules.iot.device.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.framework.json.JsonbTypeHandler;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * @author 15864
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude
@TableName("iot_device")
public class Device extends BaseEntity {

    /**
     * 设备名称
     */
    private String name;

    /**
     * 设备是否在线，默认在线
     */
    private Boolean online = true;

    /**
     * 设备状态
     */
    private Status state = Status.UNACTIVATED;

    /**
     * 硬件版本
     */
    private String hardwareVersion;

    /**
     * 固件版本
     */
    private String firmwareVersion;


    /**
     * 出厂ID
     */
    private String factoryId;


    /**
     * 客户ID
     */
    private String clientId;

    /**
     * 扩展配置
     */
    @TableField(typeHandler = JsonbTypeHandler.class)
    private List<Map<String, Object>> extendParams;

    /**
     * 设备属性
     */
    @TableField(typeHandler = JsonbTypeHandler.class)
    private List<Map<String, Object>> properties;

    /**
     * 所属产品ID
     */
    public Long productId;

    /**
     * 所属产品名称
     */
    @TableField(exist = false)
    public String productName;

    /**
     * 所属产品
     */
    @TableField(exist = false)
    public Product product;

    /**
     * 所属部门
     */
    @TableField(value = "dept_id", fill = FieldFill.INSERT)
    public Long deptId;

    /**
     * 设备经度
     */
    public Double longitude;

    /**
     * 设备纬度
     */
    public Double latitude;

    /**
     * 设备图标附件ID
     */
    public String iconId;


    /**
     * 设备预览图附件ID
     */
    public String previewId;

    /**
     * 设备是否正常运行
     */
    public Boolean deviceState;

    public enum Status implements IEnum<Integer>, IState<Status> {
        UNACTIVATED(0, "未激活"),
        LOCKED(1, "已锁定"),
        ACTIVATED(2, "已激活"),
        DISCARDED(3, "已报废");

        private final int value;
        private final String description;

        Status(int value, String description) {
            this.value = value;
            this.description = description;
        }

        @Override
        public Integer getValue() {
            return this.value;
        }

        @Override
        public String toString() {
            return this.description;
        }
    }

}

